package cn.nubia.admin.common.constant;

import cn.nubia.admin.common.springmvc.SpringContextLoader;
import cn.nubia.admin.sysconfig.bean.Menu;
import cn.nubia.admin.sysconfig.query.MenuQuery;
import cn.nubia.admin.sysconfig.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by Administrator on 2015/6/19.
 */
public class SystemConstant {
    @Autowired
    MenuService menuService;

    public static  String staticHost;

    public static List<Menu> menus = null;

    private static Integer defaultMenuId;

    public void init(){
        MenuQuery query = new MenuQuery();
        SystemConstant.menus = menuService.listMenus(query);
    }

    public  String getStaticHost() {
        return staticHost;
    }

    public void setStaticHost(String staticHost) {
        this.staticHost = staticHost;
    }

    public static Menu getMenu(Integer moduleId){
        for(Menu menu: menus){
            if(moduleId == menu.getId()){
                return menu;
            }
        }
        return menus.get(0);
    }
    public static Integer getDefaultMenuId() {
        if(defaultMenuId ==null){
            defaultMenuId = menus.get(0).getId();
        }
        return defaultMenuId;
    }

    public  void setDefaultMenuId(Integer defaultMenuId) {
        SystemConstant.defaultMenuId = defaultMenuId;
    }

    public  void setMenus(List<Menu> menus) {
        this.menus = menus;
    }
}
